<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
     @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form" >
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订阅名称">
          <a-input  v-decorator="['fdSscname', validatorRules.fdSscname]"  />
        </a-form-item>
		        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="批次">
        <!--  <a-input placeholder="请输入批次"  v-decorator="['fdBatchId', validatorRules.fdBatchId ]"  />-->
              <a-textarea placeholder="请输入批次" v-decorator="['fdBatchId', validatorRules.fdBatchId ]" :autosize="{ minRows: 1, maxRows: 1 }" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="类型">
          <j-dict-select-tag v-decorator="[ 'fdType_dictText', {}]" dictCode="run_type" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="应用工程">
          <j-dict-select-tag  v-decorator="['fdProId', {}]" placeholder="请输入应用工程" dictCode="t_sys_project,fd_projName,fd_projid" :triggerChange="true"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="运行状态">
          <j-dict-select-tag v-decorator="[ 'fdStatus_dictText', {}]" dictCode="run_status"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="业务开始日期">
          <a-date-picker showTime format="YYYY-MM-DD" v-decorator="[ 'fdBuStartDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="业务结束日期">
          <a-date-picker showTime format="YYYY-MM-DD" v-decorator="[ 'fdBuEndDate', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="运行开始时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'fdStartTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="运行结束时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'fdEndTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="运行时长">
          <a-input placeholder="请输入运行时长" v-decorator="['fdTime', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="运行参数">
          <a-input placeholder="请输入运行参数" v-decorator="['fdParam', {}]" readonly="true"/>
        </a-form-item>
       <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="错误日志">
         <a-textarea :rows="5" placeholder="请输入错误日志" v-decorator="['fdError', {} ]" />
       </a-form-item>
     <!--   <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="创建人">
          <a-input placeholder="请输入创建人" v-decorator="['createUser', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="修改人">
          <a-input placeholder="请输入修改人" v-decorator="['updateUser', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否删除">
          <a-input-number v-decorator="[ 'isDelete', {}]" />
        </a-form-item>-->
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {httpAction} from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: 'RunModal',
    components: {
      JDate,
    },
    data() {
      return {
        title: "操作",
        visible: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          fdBatchId: { rules: [] },
        },
        url: {
          add: "/run/run/add",
          edit: "/run/run/edit",
          runDetailList: '/run/run/queryRunDetailByMainId',
        }
      }
    },
    methods: {
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        //初始化明细表数据
        // console.log(this.model.id)
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'fdBatchId','fdSscid_dictText','fdSscid','fdBuStartDate','fdBuEndDate','fdSscname', 'fdType_dictText', 'fdProId', 'fdStatus_dictText', 'fdBuStartDate','','fdStartTime', 'fdEndTime', 'fdTime', 'fdParam', 'fdError', 'createUser', 'updateUser', 'isDelete', ))
          // 时间格式化
          this.form.setFieldsValue({ fdStartTime: this.model.fdStartTime ? moment(this.model.fdStartTime) : null })
          this.form.setFieldsValue({ fdEndTime: this.model.fdEndTime ? moment(this.model.fdEndTime) : null })
          this.form.setFieldsValue({ fdBuStartDate: this.model.fdBuStartDate ? moment(this.model.fdBuStartDate) : null })
          this.form.setFieldsValue({ fdBuEndDate: this.model.fdBuEndDate ? moment(this.model.fdBuEndDate) : null })
        });
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.fdStartTime = formData.fdStartTime?formData.fdStartTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.fdEndTime = formData.fdEndTime?formData.fdEndTime.format('YYYY-MM-DD HH:mm:ss'):null;
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                 that.$message.success(res.message);
                 that.$emit('ok');
               } else {
                 that.$message.warning(res.message);
               }
             }).finally(() => {
               that.confirmLoading = false;
               that.close();
             })
           }
        })
      },
      handleCancel() {
        this.close()
      }
    }
  }
</script>

<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }

  .ant-form-item-control {
    line-height: 0px;
  }

  /** 主表单行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }

  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }

</style>